package com.example.demo.test;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.example.demo.domain.Person;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@SpringBootTest
public class exportExcel01
{
    @Test
    public void test() {

        System.out.println("你妹的");
        String day = DateFormatUtils.format(System.currentTimeMillis(),"yyMMdd_HHmmss");
        StringBuilder autoFileName = new StringBuilder();
        autoFileName.append("f:\\")
                .append(day)
                .append(".xlsx");
        // 生成Excel路径
        String fileName = "f:\\workbook.xlsx";
        File file = new File("F:\\work.xls");
        //这两种都可以，一个是路径 另一种是文件
//        EasyExcel.write(fileName, Person.class).sheet(1,"每半年").doWrite(data());
//        EasyExcel.write(file, Person.class).sheet("你大爷").doWrite(data());


        List<Person> personList = new ArrayList<>();
        Person person;
        for (int i = 1; i <= 10; i++) {
            person = new Person();
            person.setName("李四" + i);
            person.setSex("女");
            person.setAge(i);
            person.setCardid(UUID.randomUUID().toString().substring(0,5));
            personList.add(person);
        }


        //方式3
        ExcelWriter excelWriter = EasyExcel.write(autoFileName.toString(),Person.class).build();
        WriteSheet writeSheet1 = EasyExcel.writerSheet(1,"日了狗").build();
        WriteSheet writeSheet2 = EasyExcel.writerSheet(2,"你大爷").build();
        excelWriter.write(personList, writeSheet1);
        excelWriter.write(data(), writeSheet2);
        excelWriter.finish();
        System.out.println("日咯");


    }


    private List<Person> data() {
        List<Person> userList = new ArrayList<>();
        Person user;
        for (int i = 1; i <= 10; i++) {
            user = new Person();
            user.setName("张三" + i);
            user.setSex("男");
            user.setAge(i);
            user.setCardid("440582xxxx");
            userList.add(user);
        }
        return userList;
    }
    @Test
    public void test05(){


        Map map = new HashMap<String,Object>();
        map.put("adi","张文迪");
        Map sychronizedMap = Collections.synchronizedMap(map);
    }



}
